package com.itheima.alipay.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Xiao
 * @version 1.0
 * @description
 * @date 2021/11/16
 */
@Controller
public class Notify {

    @RequestMapping("/notify_url")
    public void Notify(HttpServletResponse response, HttpServletRequest request) throws Exception {
        System.out.println("----------------------------notify_url------------------------");
        // 商户订单号
        String out_trade_no = new String(
                request.getParameter("out_trade_no").getBytes("ISO-8859-1"), "UTF-8");
        // 付款金额
        String total_amount = new String(
                request.getParameter("total_amount").getBytes("ISO-8859-1"), "UTF-8");
        // 支付宝交易号
        String trade_no = new String(
                request.getParameter("trade_no").getBytes("ISO-8859-1"), "UTF-8");
        // 交易说明
        String cus = new String(
                request.getParameter("body").getBytes("ISO-8859-1"), "UTF-8");
        // 交易状态
        String trade_status = new String(
                request.getParameter("trade_status").getBytes("ISO-8859-1"), "UTF-8");
        if (trade_status.equals("TRADE_SUCCESS")) {
            System.err.println("交易成功！");
        } else {
            System.err.println("交易失败！");
        }
    }
}
